#!/usr/bin/perl

##########################################################
# first argument is the file name, if the second argument
# is -d then the third arg is the desired file size (it'll
# be filled with 0's. If the second argument is -m then it
# indicates the file size should be a multiple of the 
# third arg. 
##########################################################

$size = (stat($ARGV[0]))[7];

if( $ARGV[1] eq "-d" ){
    $zeros = $ARGV[2] - $size >= 0 or die "FILL ERROR: File is too big!";
}elsif ($ARGV[1] eq "-m"){
    $zeros = $ARGV[2] - ($size % $ARGV[2]); 
}else{
    die "fatal error: fill received wrong parameters.";
}
print "Size: $size bytes\n$zeros bytes will be added\n";
system("dd if=/dev/zero of=zeros bs=$zeros count=1 ; cat zeros >> $ARGV[0]");


